{% spaceless %}

<div id="content">

{% if not messages %}
    <div id="notfound">
        <div id="notfoundtitle">404 Not Found</div>
        <div id="notfounddesc">The requested URL was not found on this server.</div>
    </div>
{% endif %}

{% for message in messages %}

    {% if message.root_post %}

        <div class="post">
            <div class="posttitle">
                {% if message.title %}
                    <a href="?u={{ message.uid }}">{{ message.title }}</a>
                {% else %}
                    <a href="?u={{ message.uid }}">(untitled)</a>
                {% endif %}
            </div>
            <div class="postmeta">
                {% if message.created_date_adayago %}
                    <span title='{{ message.created_date|date:"F j, Y \a\t f A T" }}'>{{ message.created_date|timesince }} ago</span>{% if message.comment_count %},{% endif %}
                {% else %}
                    {{ message.created_date|date:"F j, Y \a\t f A T" }}{% if message.comment_count %},{% endif %}
                {% endif %}

                {% if message.comment_count %} 
                    {{ message.comment_count }}
                    {% if message.comment_count_gt1 %} 
                        comments
                    {% else %} 
                        comment
                    {% endif %}
                {% endif %}
            </div>
            <div class="postcontent">{{ message.content|urlize|smartbr }}</div>

            {% if user.admin and uid %}
            <div id="postedit">
                <form action="/blog/" method="POST">
                    <input type="hidden" name="rt" value="POST_EDIT">
                    <input type="hidden" name="c" value="{{ category }}">
                    <input type="hidden" name="u" value="{{ uid }}">
                    <div><input type="text" name="t" size="80" value="{{ message.title }}"></div>
                    <div><textarea name="ct" rows="30" cols="90">{{ message.content }}</textarea></div>
                    <div><input type="submit" value="Post"></div>
                </form>
            </div>
            {% endif %}

        </div>

    {% else %}

        <a name="{{ message.created_date|date:"U" }}"></a>
        <div class="comment">
        <div class="rbox"><b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>

            <div class="commentavatar">
                <img {% if message.author_nickname %} alt="{{message.author_nickname|escape|slice:":30" }}" {% endif %} src="http://www.gravatar.com/avatar/{{ message.author_email_md5 }}?s=32&d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G" border="0" width="32" height="32">
            </div>

            <div class="commentmeta">
                {% if message.author_nickname %}
                    {% if message.author_url %}
                        <a href="{{ message.author_url }}"><b>{{ message.author_nickname|escape|slice:":30" }}</b></a>,
                    {% else %}
                        <b>{{ message.author_nickname|escape|slice:":22" }}</b>,
                    {% endif %}
                {% else %}
                    noname,
                {% endif %}

                {% if message.created_date_adayago %}
                    <span title='{{ message.created_date|date:"F j, Y \a\t f A T" }}'>{{ message.created_date|timesince }} ago</span>
                {% else %}
                    {{ message.created_date|date:"F j, Y \a\t f A T" }}
                {% endif %}
            </div>

            <div class="commentbody">{{ message.content|escape|urlize|linebreaksbr }}&nbsp;</div>

        <b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b></div> 
        </div>

    {% endif %}

{% endfor %}

{% if user.user and uid %}
    <div id="commentadd">
    <form action="/blog/" method="POST">
    <input type="hidden" name="rt" value="COMMENT_ADD">
    <input type="hidden" name="c" value="{{ category }}">
    <input type="hidden" name="u" value="{{ uid }}">
    <input type="text" name="nn" size="40" value="{{ user.nickname }}"> | <b>Name</b><br>
    <input type="text" name="url" size="40"> | <b>URL</b> (optional)
    <div><textarea name="ct" rows="6" cols="60"></textarea></div>
    <div><input type="submit" value="Post"></div>
    </form>
    </div>
{% endif %}

{% if user.admin and not uid %}
    <div id="postadd">
    <form action="/blog/" method="POST">
    <input type="hidden" name="rt" value="POST_ADD">
    <input type="hidden" name="c" value="{{ category }}">
    <div><input type="text" name="t" size="80"></div>
    <div><textarea name="ct" rows="12" cols="80"></textarea></div>
    <div><input type="submit" value="Post"></div>
    </form>
    </div>
{% endif %}

</div>

<div id="navigation">
    {% if cur_page %}
        {% if prev_page %} 
            <a href="?p={{ prev_page }}">Previous</a> |
        {% else %}
            Previous |
        {% endif %}
    
        {% if next_page %} 
            <a href="?p={{ next_page }}">Next</a> 
        {% else %}
            Next
        {% endif %}
    {% endif %}
</div>

{% endspaceless %}
